package com.example.snack1;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class FirstTask implements Runnable{
    private static final String TAG = "RateTask";
    Handler handler;


    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    @Override
    public void run() {
        Log.i(TAG, "run: ......");
        Document doc = null;
        try {
            doc = Jsoup.connect("http://www.lingshitx.com/").get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //Log.i(TAG, "doc:" + doc);
        Log.i(TAG, "title:" + doc.title());


        Elements div = doc.getElementsByTag("div");
        Log.i(TAG, "ul=" + div);
        //Elements lis = ul.getElementsByTag("li");
        //List<String> list1=new ArrayList<String>();
        List<FirstPage> ret=new ArrayList<>();

/*
        for (Element li : lis) {
            Elements a = li.getElementsByTag("a");
            Elements span = li.getElementsByTag("span");
            Log.i(TAG, "run:a=" + a);
            Log.i(TAG, "run:span=" + span);
            //if (a.size() > 0) {
                String str = a.text();
                Log.i(TAG, "run: str=" + str);
                String val =span.text();
                Log.i(TAG, "run: val=" + val);
                ret.add(new FirstPage(str,val));


                //list1.add(str + "->" + val);
           // }
           }

 */



        //Message msg = handler.obtainMessage(11, ret);
        //handler.sendMessage(msg);
    }
}
